package com.cuitrip.util.text;

import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.cuitrip.component.item.ItemLayout;
import com.cuitrip.service.R;
import com.cuitrip.util.ResourceUtil;

/**
 * 文字设置逻辑
 * Created by ak on 15/9/23.
 */
public class TextProxy {

    private static TextProxy sInstance;

    public static TextProxy getInstance() {
        if (null == sInstance)
            sInstance = new TextProxy();
        return sInstance;
    }

    public void showTextAsNull(TextView textView){
        textView.setText(R.string.value_no_set);
    }

    public void setTextOrAsGone(ItemLayout itemLayout, CharSequence text){
        if (TextUtils.isEmpty(text)){
            itemLayout.setVisibility(View.GONE);
        }else{
            itemLayout.setVisibility(View.VISIBLE);
            itemLayout.setmRightText(text);
        }
    }


    public String formatWithSingleAndMore(Object value, int singleResString, int multiResString){
        int valueInt  = 0;
        if (value instanceof Integer){
            valueInt = (int) value;
        }else if (value instanceof String){
            valueInt  = Integer.parseInt((String) value);
        }

        if (valueInt > 1){
            return ResourceUtil.getString(multiResString, valueInt);
        }else{
            return ResourceUtil.getString(singleResString, valueInt);
        }
    }

    /**
     *
     * @return
     */
    public int getResStringFromValue(Object value, int singleResString, int multiResString){
        int valueInt  = 0;
        if (value instanceof Integer){
            valueInt = (int) value;
        }else if (value instanceof String){
            valueInt  = Integer.parseInt((String) value);
        }

        if (valueInt > 1){
            return multiResString;
        }else{
            return singleResString;
        }
    }


}
